package org.extend;
// 添加成员对象类
class MemberObject {
    private String name;

    public MemberObject(String name) {
        this.name = name;
        System.out.println(name + " 成员对象被初始化");
    }
}

class FinalMethod {
    // 添加父类成员对象
    private MemberObject parentMember1 = new MemberObject("父类-成员1");
    private static MemberObject staticParentMember = new MemberObject("父类-静态成员");

    public FinalMethod() {
        System.out.println("父类构造器被调用");
    }
    // 添加父类第二个成员对象
    private MemberObject parentMember2 = new MemberObject("父类-成员2");
    // 添加父类静态代码块
    static {
        System.out.println("父类静态代码块执行");
    }
    // 添加父类实例代码块
    {
        System.out.println("父类实例代码块执行");
    }
}

class OverrideFinal extends FinalMethod {
    // 添加子类成员对象
    private MemberObject childMember1 = new MemberObject("子类-成员1");
    private static MemberObject staticChildMember = new MemberObject("子类-静态成员");

    public OverrideFinal() {
        System.out.println("子类构造器被调用");
    }

    // 添加子类第二个成员对象
    private MemberObject childMember2 = new MemberObject("子类-成员2");

    // 添加子类静态代码块
    static {
        System.out.println("子类静态代码块执行");
    }

    // 添加子类实例代码块
    {
        System.out.println("子类实例代码块执行");
    }
}

class FinalOverrideEx {
    public static void main(String[] args) {
        System.out.println("=== 开始创建子类实例 ===");
        OverrideFinal of = new OverrideFinal();
        System.out.println("=== 子类实例创建完成 ===");

        System.out.println("\n=== 父类引用指向子类对象 ===");
        FinalMethod wf = of;  // 向上转型
    }
}
